import time

from selenium.webdriver.common.by import By

from common.Utils import BlogDriver

class BlogEditTest:
    url=""
    driver=""

    def __init__(self):
        self.url="http://8.137.19.140:9090/blog_edit.html"
        self.driver=BlogDriver.driver
        self.driver.get(self.url)

    #异常发布博客
    def EditFailTest(self):
        #不输入标题
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        time.sleep(2)
        alert=self.driver.switch_to.alert
        alert.accept()
        BlogDriver.getScreenShot()

    #正常发布博客
    def EditSucTest(self):
        #菜单栏是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#editor > div.CodeMirror.cm-s-default.CodeMirror-wrap")
        #发布一个名为“这是一个自动化测试”的博客
        self.driver.find_element(By.CSS_SELECTOR,"#title").send_keys("这是一个自动化测试")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        actual=self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(542) > div.title").text
        assert actual=="这是一个自动化测试"
        BlogDriver.getScreenShot()

